home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.GridLayout;
- import java.awt.Image;
- import java.awt.Panel;
- import java.awt.image.MemoryImageSource;
-
- class ImagePanel extends Panel {
- Applet applet;
-
- public ImagePanel(Applet app) {
- this.applet = app;
- ((Container)this).setLayout(new BorderLayout());
- Panel grid = new Panel();
- ((Container)grid).setLayout(new GridLayout(0, 2));
- ((Container)this).add("Center", grid);
- ((Container)grid).add(new ImageCanvas(this.applet, this.makeDitherImage(), (double)0.5F));
- Image joe = this.applet.getImage(this.applet.getDocumentBase(), "graphics/joe.surf.yellow.small.gif");
- ((Container)grid).add(new ImageCanvas(this.applet, joe, (double)1.0F));
- ((Component)this).reshape(0, 0, 20, 20);
- }
-
- Image makeDitherImage() {
- int w = 100;
- int h = 100;
- int[] pix = new int[w * h];
- int index = 0;
-
- for(int y = 0; y < h; ++y) {
- int red = y * 255 / (h - 1);
-
- for(int x = 0; x < w; ++x) {
- int blue = x * 255 / (w - 1);
- pix[index++] = -16777216 | red << 16 | blue;
- }
- }
-
- return this.applet.createImage(new MemoryImageSource(w, h, pix, 0, w));
- }
- }
-